<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="author" content="hexinyang">	
	<title>补卡</title>
	<script language="javascript" type="text/javascript" src="../script/print.js"></script>
	<script language="javascript" src="../script/common.js"  type="text/javascript" ></script>
	<script language="javascript" src="../script/card.js" type="text/javascript" ></script>
	<script type="text/javascript" >	
		//页面加载方法	
		var oldCardType;
		function load(){			
			Eui.showNavigation();
			setPages(["detview","readcardview"]);
			CardMgnt.cardUser.show("userinfo_div");
		}
		//查询显示信息明细
		function searchCard(){
			if(!checkForm(cardForm))return;			
			var asn = cardForm.oldAsn.value;
			DWR.call("mgntQueryService.checkRenewCard",asn,function(data){
				oldCardType = data.cardType;
				var ct = data.cardType;
				cardForm.cardType.value = ct.id
				cardForm.oldCardTypeName.value = ct.name;
				cardForm.oldAsn.readOnly = true;
				cardForm.feeAmount.value = Format.fenToYuan(CardMgnt.getFee(Constants.ACCOUNT_FEE_RENEW_CARD,ct.id));
			
				CardMgnt.cardUser.showData("userinfo_div",data);
				
				var bObj = {}
				bObj.spareBalance = Format.fenToYuan(data.balanceMap?data.balanceMap.balance:0);
				bObj.spareLoyaltyBalance = Format.fenToYuan(data.balanceMap?data.balanceMap.loyaltyBalance:0);
				Common.setValues(balanceForm,bObj);
					
				$("queryOldCardBtn").disabled = true;
				$("readNewCardBtn").disabled = false;
			});
		}
		
		//重置方法
		function onCancel(){
			switchPage("readcardview");
			CardMgnt.resetForm(cardForm)
			cardForm.reset();
			balanceForm.reset();
			CardUserViewForm.reset();
			
			cardForm.oldAsn.readOnly = false;
			$("changeCardBtn").disabled = true;
			$("readNewCardBtn").disabled = true;
			$("queryOldCardBtn").disabled = false;
		}
		
		//读新卡
		function onReadCard(){
			var asn;
			try{
				getCard();
				asn = getAsn();
			}catch(e){showError(e.description);return;}
			
			cardForm.newAsn.value = asn;
			
			DWR.call("mgntQueryService.checkInitedCard",asn,function(data){
				var currentLevel = $(CardMgnt.cardUser.formName).currentLevel.value;
				var cardType = data.cardType;
				if (cardType.baseCardType != oldCardType.baseCardType || oldCardType.anonymous !== cardType.anonymous){
					showWarning("该客户级别不能领取该卡！");return;
				}
				if (currentLevel < data.cardType.userLevel){
					showWarning("该客户级别不能领取该类型("+cardType.name+")卡！");return;
				}
				
				var foregiftAmount = CardMgnt.getFee(Constants.ACCOUNT_FOREGIFT_CARD,data.cardType.id);
				cardForm.newForegift.value = Format.fenToYuan(foregiftAmount);
				cardForm.newCardTypeName.value = data.cardType.name;
				$("changeCardBtn").disabled = false;
			});
		}
		
		//补卡方法
		function renewCard(){
			var oldAsn = cardForm.oldAsn.value;
			var newAsn = cardForm.newAsn.value;
			if (!CardMgnt.checkCardAsn(newAsn)) return;
			DWR.call("cardMgntService.renewCard",oldAsn,newAsn,function(data){
				var str = "补卡成功！<br>新卡卡号为："+newAsn+"<br>备用金余额为："+Format.fenToYuan(data.balance)+"元";
				str += "<br>备用积分余额为：" + Format.fenToYuan(data.pointBalance) + "点";
				showInformation(str);
				switchPage("detview");
				CardMgnt.showPrintView("detview","renewCard_bill",data.logId,"补卡凭证");
				try{
					WebPrint.print("billview");
				}catch(e){
					showError("打印单据出错:"+e.description);
				}
				while(true){
					try{
						CardMgnt.syncCardData(newAsn);
						break;
					}catch(e){
						if (showQuestion("同步卡数据失败！是否重试？<br>错误："+e.description)) continue;
						
						if(showQuestion("同步卡数据失败！是否换卡？")){
							CardMgnt.badCard.gotoPage(newAsn,CardMgnt.badCard.RENEW);
						}
						return;
					}
				}
				
				if (data.cardUser.usePin){
					CardMgnt.startCardPin(newAsn);
				}
			},{blockScreen:true});
		}
	</script>
</head>
<body onload="load()" onunload="releaseCard()">
	<!--页面导航-->
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<div id="readcardview">
		<div class="form">
			<div id="userinfo_div">
			</div>
			<form id="balanceForm" name="balanceForm">
				<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="col2 label6">
					<tr>
						<td><label>备用金余额</label> <input type="text" name="spareBalance" readonly class="readonly"> 元</td>
						<td><label>备用积分余额</label> <input type="text" name="spareLoyaltyBalance" readonly class="readonly">&nbsp;&nbsp;</td>
					</tr>
				</table>
			</form>
		</div>
		<div class="form">
			<form id="cardForm" name="cardForm">
				<input type="hidden" name="cardType">
				<div class="formTitle">卡片信息</div>
				<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="col2 label6">
					<tr>
						<td><label>旧卡卡号</label> <input type="text" name="oldAsn" onblur="checkV(this,'asn',true)"><span class="des">*</span></td>
						<td><label>新卡卡号</label> <input type="text" name="newAsn" readonly class="readonly">&nbsp;&nbsp;</td>
					</tr>
				</table>
				<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="col2 label6">
					<tr>
						<td><label>旧卡卡类型</label> <input type="text" name="oldCardTypeName" readonly class="readonly"></td>
						<td><label>新卡卡类型</label> <input type="text" name="newCardTypeName" readonly class="readonly"></td>
					</tr>
				</table>
				<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="col2 label6">
					<tr>
						<td><label>手续费</label> <input type="text" name="feeAmount" readonly class="readonly">&nbsp;&nbsp;</td>
						<td><label>新卡押金</label> <input type="text" name="newForegift" readonly class="readonly"></td>
					</tr>
				</table>
			</form>
		</div>
		<p>
			<button id="queryOldCardBtn" onclick="searchCard()">查询旧卡</button>
			<button id="readNewCardBtn" onclick="onReadCard()" disabled>读 新 卡</button>
			<button id="changeCardBtn" onclick="renewCard()" disabled>补 卡</button>
			<button onclick="onCancel()">重 置</button>
		</p>
	</div>
	
	<!--凭证页面-->
	<div id="detview" style="display:none;">
	</div>
</body>
</html>